
function openModal(modal) {
	modal = modal || true;

	$("#modal_message")
			.dialog(
					{
						modal : modal,
						autoOpen : true,
						height : 250,
						width : 300,
						resizable : false,
						draggable : false,
						buttons : [ {
							html : '<span class="ui-icon ui-icon-closethick"></span>&nbsp;<span class="ui-button-text">Close</span>',
							click : function() {
								$(this).dialog("close").dialog("destroy");
							}
						} ]
					});
}

function loadJS(src,callback,cache){
	cache = cache || true,

	$.ajax({
		type: "get",
	  	url: src,
	  	cache: cache,
	  	global: false,
	  	dataType: "script",
	  	success: function(){
			if(callback) {
				callback();
			}
		}
	});
	
}

function showDialog(json,modal) {
	modal = modal || false;
	if (!$.isPlainObject(json)) {
		_debugMsg = 0;
		json = {
			"header" : "Response Error",
			"message" : "Malformed system response - null"
		};
		modal = true;
		$("#modal_message").attr('title', json.header).html(json.message);

	} else {
		
		if (json.error == '0') {
			_debugMsg = _debugMsg && 0;
		}
		
		$("#modal_message").attr('title', json.header).html(json.message);

		if (_debugMsg) {
			$("#modal_message").append($('#tmpl_admin_debug').jqote(json));
		}

	}
	openModal(modal);
}



/**
 *
 */
$(function(){

    var _modalWait = $('#modal_wait');
    
    function bindAjax(){
    _modalWait.on('ajaxStart.mine',function(a,b,c){
		console.log("ajaxStart");
        $(this).dialog({
            modal: true,
            resizable: false,
            draggable: false,
            autoOpen: true
        });
    });
    
    _modalWait.on('ajaxComplete.mine',function(){
    	console.log("ajaxComplete");
		$(this).dialog("close").dialog("destroy");
    });
    }
	
    _modalWait.on('ajaxError.mine',function(){
    	console.log("ajaxError");
    	showDialog("");
        $(this).dialog("close").dialog("destroy");
    });	

    
    $('#wr-rightcontent button').button();

	var _rightcontent = $('#wr-rightcontent');

	var originalFontSize = _rightcontent.css('font-size');

	$(".resetFont").click(function() {

		_rightcontent.css('font-size', originalFontSize);

		return false;

	});

	$(".increaseFont").click(function() {

		var currentFontSize = _rightcontent.css('font-size');

		var currentFontSizeNum = parseFloat(currentFontSize, 10);

		var newFontSize = currentFontSizeNum * 1.2;
		console.log(currentFontSize);
		console.log(currentFontSizeNum);
		console.log(newFontSize);

		_rightcontent.css('font-size', newFontSize);


		return false;

	});

	$(".decreaseFont").click(function() {

		var currentFontSize = _rightcontent.css('font-size');

		var currentFontSizeNum = parseFloat(currentFontSize, 10);

		var newFontSize = currentFontSizeNum * 0.8;

		_rightcontent.css('font-size', newFontSize);

		return false;

	});

	$('.ui-form .chzn-select').chosen().css('display', '').addClass(
			'ui-helper-hidden-accessible');

	$('.ui-form ul:not(.no-stripes)').each(function(a, b) {
		$(this).find('li:not(.ui-widget-header,.active-result)').each(function(i, v) {
			var k = (i % 2);
			k++;
			$(this).addClass('bg0' + k);
		});
	});
	
	$('.ui-form ul:not(.no-stripes)>li:last-child').addClass('bbottom');

    $('body').on('click', '.select-all', function(e){
        $(this).focus();
        $(this).select();
    });	
    
	$('#wrapper-preload').hide();
	$('#wrapper').removeClass('ui-helper-hidden-accessible');

});


